﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using static GridLoaction.GridPacker;

namespace GridLoaction
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();

            Container container = new Container(0, 0, 5000, 3000, 20);
            List<Rectangle> doorsList = new List<Rectangle>()
            {
                new Rectangle(0, 0, 1000, 1000),
            };


            int cabinetWidth = 1200;
            int cabinetHeight = 600;
            GridPacker gridPacker = new GridPacker();
            List<Rectangle> rectangles = gridPacker.GetResults(container,doorsList,cabinetWidth,cabinetHeight);

            for (int i = 0; i < rectangles.Count; i++)
            {
                System.Windows.Shapes.Rectangle parent = new System.Windows.Shapes.Rectangle
                {
                    Width = 200,
                    Height = 120,
                    Fill = new SolidColorBrush(System.Windows.Media.Color.FromArgb(255, 0, 0, 255)),
                };
                double x = i % 4 * (200 + 10);
                double y = i / 4 * (120 + 10);
                Canvas.SetLeft(parent, x);
                Canvas.SetTop(parent, y);
                myCanvas.Children.Add(parent);

                Rectangle rect = rectangles[i];

                System.Windows.Shapes.Rectangle child = new System.Windows.Shapes.Rectangle
                {
                    Width = rect.Width*1.0/25,
                    Height = rect.Height * 1.0 / 25,
                    Fill = new SolidColorBrush(System.Windows.Media.Color.FromArgb(255, 255, 222, 0)),
                };
                double childX = x + rect.X * 1.0 / 25;
                double childY = y + rect.Y * 1.0 / 25;
                Canvas.SetLeft(child, childX);
                Canvas.SetTop(child, childY);
                myCanvas.Children.Add(child);


                foreach (Rectangle item in doorsList)
                {
                    System.Windows.Shapes.Rectangle door = new System.Windows.Shapes.Rectangle
                    {
                        Width = item.Width * 1.0 / 25,
                        Height = item.Height * 1.0 / 25,
                        Fill = new SolidColorBrush(System.Windows.Media.Color.FromArgb(255, 255, 0, 0)),
                    };
                    double doorX = x + item.X * 1.0 / 25;
                    double doorY = y + item.Y * 1.0 / 25;
                    Canvas.SetLeft(door, doorX);
                    Canvas.SetTop(door, doorY);
                    myCanvas.Children.Add(door);
                }

            }


        }
    }
}
